﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BoAddonBiz_FreightForwarder.BusinessBase;
using SAPbouiCOM;

namespace BoAddonBiz_FreightForwarder.Land
{
    [ControlB1FormAttribute(IsNew = true, FormType = B1FormTypes.ado_AVA_LN_Delegate)]
    class B1Form_Delegate_Land : B1Form_Delegate_Base
    {
        #region override
        protected override string AVA_ODLG { get { return "@AVA_LN_ODLG"; } }
        protected override string AVA_DLG1 { get { return "@AVA_LN_DLG1"; } }
        protected override string AVA_DLG2 { get { return "@AVA_LN_DLG2"; } }
        protected override string AVA_DLG3 { get { return "@AVA_LN_DLG3"; } }
        protected override string AVA_DLG4 { get { return "@AVA_LN_DLG4"; } }
        protected override string AVA_OQOT { get { return "@AVA_LN_OQOT"; } }
        protected override string AVA_QOT3 { get { return "@AVA_LN_QOT3"; } }
        protected override string AVA_OSOD { get { return "@AVA_LN_OSOD"; } }
        protected override string AVA_SOD1 { get { return "@AVA_LN_SOD1"; } }
        protected override string AVA_SOD2 { get { return "@AVA_LN_SOD2"; } }
        protected override string AVA_SOD3 { get { return "@AVA_LN_SOD3"; } }
        protected override string BusinessType { get { return "LN"; } }
        protected override string TargetObject { get { return "AVA_LN_BusinessOpera"; } }
        protected override string SourceSalesOrderObject { get { return "AVA_LN_SalesOrder"; } }
        protected override string SourceQuoteObject { get { return "AVA_LN_Quote"; } }
        protected override string[] SumMapping
        {
            get { return new string[] { "U_Quantity:U_Quantity", "U_GrossWeight:U_GrossWeight", "U_BillingWeight:U_BillingWeight", "U_Volume:U_Volume", "U_CargoValue:U_CargoValue" }; }
        }
        protected override void FormInfoSetting(SAPBoAddon.B1FormSetting FormSetting)
        {
            FormSetting.FormType = B1FormTypes.ado_AVA_LN_Delegate;
            FormSetting.FormFileName = B1FormTypes.ado_AVA_LN_Delegate.ToString() + "Form.srf";
            base.FormInfoSetting(FormSetting);
        }
        #endregion
        public B1Form_Delegate_Land()
        {
            this.frm_ChooseFormListEvent += new SAPBoAddon.IB1FormEvents.B1ChooseFormListEventEventHandler(B1Form_Delegate_Land_frm_ChooseFormListEvent);
        }

        void B1Form_Delegate_Land_frm_ChooseFormListEvent(SAPBoAddon.B1AddonBase.B1ChooseFormList pVal, ref bool BubbleEvent)
        {
            SAPbouiCOM.Matrix omtx = default(SAPbouiCOM.Matrix);
            SAPbouiCOM.DBDataSource dbds = default(SAPbouiCOM.DBDataSource);
            SAPbouiCOM.Conditions cons;
            SAPbouiCOM.Condition con;
            SAPbouiCOM.ChooseFromList cfl;
            SAPbobsCOM.Recordset oRst = (SAPbobsCOM.Recordset)SBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
            if (pVal.BeforeAction)
            {
                cfl = this.CurrentForm.ChooseFromLists.Item(pVal.ChooseFromListUID);
                switch (pVal.ChooseFromListUID)
                {
                    case "CFL_EPAgencyNameCardCode"://目的港代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_TPAgencyNameCardCode"://中转港代理
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                    case "CFL_SPAgencyInfoCardCode"://订舱代理
                    case "CFL_CarrierNameCardCode"://承运人 
                        cons = new SAPbouiCOM.Conditions();
                        con = cons.Add();
                        con.Alias = "QryGroup5";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup6";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_OR;
                        con = cons.Add();
                        con.Alias = "QryGroup7";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        con.Relationship = BoConditionRelationship.cr_AND;
                        con = cons.Add();
                        con.Alias = "validFor";
                        con.CondVal = "Y";
                        con.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
                        cfl.SetConditions(cons);
                        break;
                }
            }
        }
    }
}
